package jh.com.jhappbf.fragmentactivity;

import android.content.Intent;
import android.os.Bundle;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentManager;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;

import jh.com.jhappbf.R;
import jh.com.jhappbf.ui.CalendarActivity;

/**
 * @author Administrator
 */
public abstract class SingleFragmentActivity extends FragmentActivity implements OnClickListener {

    public abstract Fragment createFragment();

    private ImageView mBackImageView;
    private TextView mTitleTextView;
    private TextView txtSetting1;
    private TextView txtSetting2;

    @Override
    protected void onCreate(Bundle arg0) {
        super.onCreate(arg0);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.single_fragment_activity);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        findView();
        setListener();
        FragmentManager fm = getSupportFragmentManager();
        Fragment fragment = fm.findFragmentById(R.id.ui_singleActivity_frame);
        if (fragment == null) {
            fm.beginTransaction().add(R.id.ui_singleActivity_frame, createFragment()).commit();
        }
    }

    /**
     * 查找控件
     */
    private void findView() {
        mBackImageView = findViewById(R.id.ui_singleActivity_comeback);
        mTitleTextView = findViewById(R.id.ui_singleActivity_title);
        txtSetting1 = findViewById(R.id.ui_singleActivity_txt1);
        txtSetting2 = findViewById(R.id.ui_singleActivity_txt2);
        mTitleTextView.setText("化验查询");
    }

    /**
     * 设置监听器
     */
    private void setListener() {
        mBackImageView.setOnClickListener(this);
        txtSetting1.setOnClickListener(this);
        txtSetting2.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.ui_singleActivity_comeback:
                this.finish();
                break;
            case R.id.ui_singleActivity_txt2:
                Intent intent = new Intent(SingleFragmentActivity.this, CalendarActivity.class);
                startActivityForResult(intent, 1);
                break;
            case R.id.ui_singleActivity_txt1:
                Intent i = new Intent(SingleFragmentActivity.this, MyFragmentActivity.class);
                i.putExtra("flag", "cargoName");
                startActivityForResult(i, 2);
            default:
                break;
        }
    }
}
